#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Config.hpp>

#define FRAME_TIME 100

int walking = 0;
int standing = 0;
int Combo = 0; 
int UpAtt = 0;
int ComUp = 0;
int WalkBlok = 0;

int main()
{
    sf::RenderWindow window(sf::VideoMode(1000, 700, 32), "Naruto");

		sf::Image stand1, stand2, stand3, stand4, walk1, walk2, walk3, walk4, walk5, walk6, combo1, combo2, combo3, tlo1, tlo2, upatt1, upatt2, upatt3, upatt4, upatt5,
			comUp1, comUp2, comUp3, comUp4, comUp5, comUp6, comUp7, comUp8, comUp9, comUp10, comUp11, comUp12, comUp13, comUp14;
		
		stand1.LoadFromFile(".\\Sprite\\Sasuke\\sasuke.tga");
		stand2.LoadFromFile(".\\Sprite\\Sasuke\\sasuke2.tga");
		stand3.LoadFromFile(".\\Sprite\\Sasuke\\sasuke3.tga");
		stand4.LoadFromFile(".\\Sprite\\Sasuke\\sasuke4.tga");

        walk1.LoadFromFile(".\\Sprite\\Sasuke\\walk1.tga");
        walk2.LoadFromFile(".\\Sprite\\Sasuke\\walk2.tga");
        walk3.LoadFromFile(".\\Sprite\\Sasuke\\walk3.tga");
        walk4.LoadFromFile(".\\Sprite\\Sasuke\\walk4.tga");
        walk5.LoadFromFile(".\\Sprite\\Sasuke\\walk5.tga");
        walk6.LoadFromFile(".\\Sprite\\Sasuke\\walk6.tga"); 

		combo1.LoadFromFile(".\\Sprite\\Sasuke\\combo1.tga");
		combo2.LoadFromFile(".\\Sprite\\Sasuke\\combo2.tga");
		combo3.LoadFromFile(".\\Sprite\\Sasuke\\combo3.tga");

		upatt1.LoadFromFile(".\\Sprite\\Sasuke\\upatt1.tga");
        upatt2.LoadFromFile(".\\Sprite\\Sasuke\\upatt2.tga");
        upatt3.LoadFromFile(".\\Sprite\\Sasuke\\upatt3.tga");
        upatt4.LoadFromFile(".\\Sprite\\Sasuke\\upatt4.tga");
        upatt5.LoadFromFile(".\\Sprite\\Sasuke\\upatt5.tga");

		comUp1.LoadFromFile(".\\Sprite\\Sasuke\\comUp1.tga");
		comUp2.LoadFromFile(".\\Sprite\\Sasuke\\comUp2.tga");
		comUp3.LoadFromFile(".\\Sprite\\Sasuke\\comUp3.tga");
		comUp4.LoadFromFile(".\\Sprite\\Sasuke\\comUp4.tga");
		comUp5.LoadFromFile(".\\Sprite\\Sasuke\\comUp5.tga");
		comUp6.LoadFromFile(".\\Sprite\\Sasuke\\comUp6.tga");
		comUp7.LoadFromFile(".\\Sprite\\Sasuke\\comUp7.tga");
		comUp8.LoadFromFile(".\\Sprite\\Sasuke\\comUp8.tga");
		comUp9.LoadFromFile(".\\Sprite\\Sasuke\\comUp9.tga");
		comUp10.LoadFromFile(".\\Sprite\\Sasuke\\comUp10.tga");
		comUp11.LoadFromFile(".\\Sprite\\Sasuke\\comUp11.tga");
		comUp12.LoadFromFile(".\\Sprite\\Sasuke\\comUp12.tga");
		comUp13.LoadFromFile(".\\Sprite\\Sasuke\\comUp13.tga");
		comUp14.LoadFromFile(".\\Sprite\\Sasuke\\comUp14.tga");

        tlo1.LoadFromFile(".\\Sprite\\tlo1.tga");
		tlo2.LoadFromFile(".\\Sprite\\tlo2.tga");

		sf::Texture standTexture1;
		sf::Texture standTexture2;
		sf::Texture standTexture3;
		sf::Texture standTexture4;

        sf::Texture walkTexture2;
        sf::Texture walkTexture3;
        sf::Texture walkTexture4;
        sf::Texture walkTexture5;
        sf::Texture walkTexture6;
        sf::Texture walkTexture7;

		sf::Texture upattTexture1;
        sf::Texture upattTexture2;
        sf::Texture upattTexture3;
        sf::Texture upattTexture4;
        sf::Texture upattTexture5;

		sf::Texture comboTexture1;
        sf::Texture comboTexture2;
        sf::Texture comboTexture3;

		sf::Texture comUpTexture1;
		sf::Texture comUpTexture2;
		sf::Texture comUpTexture3;
		sf::Texture comUpTexture4;
		sf::Texture comUpTexture5;
		sf::Texture comUpTexture6;
		sf::Texture comUpTexture7;
		sf::Texture comUpTexture8;
		sf::Texture comUpTexture9;
		sf::Texture comUpTexture10;
		sf::Texture comUpTexture11;
		sf::Texture comUpTexture12;
		sf::Texture comUpTexture13;
		sf::Texture comUpTexture14;

        sf::Texture charTlo1;
		sf::Texture charTlo2;

		standTexture1.LoadFromImage(stand1);
		standTexture2.LoadFromImage(stand2);
		standTexture3.LoadFromImage(stand3);
		standTexture4.LoadFromImage(stand4);

        walkTexture2.LoadFromImage(walk1);  
        walkTexture3.LoadFromImage(walk2);
        walkTexture4.LoadFromImage(walk3);
        walkTexture5.LoadFromImage(walk4);
        walkTexture6.LoadFromImage(walk5);
        walkTexture7.LoadFromImage(walk6);

		upattTexture1.LoadFromImage(upatt1);
        upattTexture2.LoadFromImage(upatt2);
        upattTexture3.LoadFromImage(upatt3);
        upattTexture4.LoadFromImage(upatt4);
        upattTexture5.LoadFromImage(upatt5);

		comboTexture1.LoadFromImage(combo1);
        comboTexture2.LoadFromImage(combo2);
        comboTexture3.LoadFromImage(combo3);

		comUpTexture1.LoadFromImage(comUp1);
		comUpTexture2.LoadFromImage(comUp2);
		comUpTexture3.LoadFromImage(comUp3);
		comUpTexture4.LoadFromImage(comUp4);
		comUpTexture5.LoadFromImage(comUp5);
		comUpTexture6.LoadFromImage(comUp6);
		comUpTexture7.LoadFromImage(comUp7);
		comUpTexture8.LoadFromImage(comUp8);
		comUpTexture9.LoadFromImage(comUp9);
		comUpTexture10.LoadFromImage(comUp10);
		comUpTexture11.LoadFromImage(comUp11);
		comUpTexture12.LoadFromImage(comUp12);
		comUpTexture13.LoadFromImage(comUp13);
		comUpTexture14.LoadFromImage(comUp14);

        charTlo1.LoadFromImage(tlo1);
		charTlo2.LoadFromImage(tlo2);

		sf::Sprite charSprite1(standTexture1);
        sf::Sprite SpriteTlo1( charTlo1 );
		sf::Sprite SpriteTlo2( charTlo2 );
		sf::Sprite przeciwnik(standTexture1);

        charSprite1.SetPosition ( 300, 600 );

        sf::Clock clock;

        sf::Clock walk;
		
		sf::Clock kombo;

		sf::Clock blok;

		sf::Clock upattack;

		sf::Clock comup;

		bool doubleclick = false;

        bool goingLeft = false;

        while ( window.IsOpen() )
        {
                sf::Event zdarzenie;

                while ( window.PollEvent( zdarzenie ) )
                {
                        if ( zdarzenie.Type == sf::Event::Closed )
                                window.Close();
                }

                                if(clock.GetElapsedTime() >= 33)
                                {
                                        if ( sf::Keyboard::IsKeyPressed ( sf::Keyboard::Right ) && !ComUp > 0 && !Combo > 0 && !UpAtt > 0 )
                                        {
												 walking = (walking + 1) % 5;
												 WalkBlok = ( WalkBlok + 1 );

                                                if(goingLeft)
                                                {
                                                        goingLeft = false;
                                                        charSprite1.Scale ( -1, 1 );
                                                        charSprite1.Move ( -80, 0 );
                                                }

                                                charSprite1.Move ( 5, 0 );
                                        }
										else if ( sf::Keyboard::IsKeyPressed ( sf::Keyboard::Left ) && !ComUp > 0 && !Combo > 0 && !UpAtt > 0 )
                                        {
                                                walking = (walking + 1) % 5;
												WalkBlok = ( WalkBlok + 1 );

                                                if(!goingLeft)
                                                {
                                                        goingLeft = true;
                                                        charSprite1.Scale ( -1, 1 );
                                                        charSprite1.Move ( 80, 0 );
                                                }

                                                charSprite1.Move ( -5, 0 );
                                        }
                                        clock.Reset();

										if ( !sf::Keyboard::IsKeyPressed ( sf::Keyboard::Right ) &&
										!sf::Keyboard::IsKeyPressed ( sf::Keyboard::Left ) )
                                        {
                                              charSprite1.SetTexture ( standTexture1 );
											  WalkBlok = 0;
											  walking = 0;
                                        }
                                }

                                        if ( sf::Keyboard::IsKeyPressed ( sf::Keyboard::Right ) && walk.GetElapsedTime() >= 200 ||
										sf::Keyboard::IsKeyPressed ( sf::Keyboard::Left ) && walk.GetElapsedTime() >= 200 )
                                        {
											switch(walking)

											{
                                                case 0: charSprite1.SetTexture ( walkTexture2 ); break;
                                                case 1: charSprite1.SetTexture ( walkTexture3 ); break;
                                                case 2: charSprite1.SetTexture ( walkTexture4 ); break;
                                                case 3: charSprite1.SetTexture ( walkTexture5 ); break;
                                                case 4: charSprite1.SetTexture ( walkTexture6 ); break;
                                                case 5: charSprite1.SetTexture ( walkTexture7 ); break;
											}
											walk.Reset();
										}

								if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Z) && Combo == 0 && !UpAtt > 0 && !WalkBlok > 0 ||
									Combo > 0 && kombo.GetElapsedTime() > 200 )
									{
										Combo++;
										kombo.Reset(); 
									}

										switch ( Combo ) 
										{
											case 1: charSprite1.SetTexture ( comboTexture1 ); break;
											case 2: charSprite1.SetTexture ( comboTexture2 ); break;
											case 3: charSprite1.SetTexture ( comboTexture3 ); break;
											case 4:
													Combo = 0;
													charSprite1.SetTexture ( standTexture1 );
													break;
										}

								if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Up ) && UpAtt == 0 && !WalkBlok > 0 ||
									UpAtt > 0 && upattack.GetElapsedTime() > 200) 
								{
									if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Z ) && UpAtt == 0 && !WalkBlok > 0 ||
									UpAtt > 0 && upattack.GetElapsedTime() > 200) 
									 {
										UpAtt++;
										upattack.Reset();
									 }
								}

								switch ( UpAtt )
								{	
								case 1: charSprite1.SetTexture ( upattTexture1 ); break;
								case 2: charSprite1.SetTexture ( upattTexture2 ); break;
								case 3: charSprite1.SetTexture ( upattTexture3 ); break;
								case 4: charSprite1.SetTexture ( upattTexture4 ); break;
								case 5: charSprite1.SetTexture ( upattTexture5 ); break;
								case 6: UpAtt = 0;
										charSprite1.SetTexture ( standTexture1 ); 
										break;
								}

								if(sf::Keyboard::IsKeyPressed(sf::Keyboard::X ) && sf::Keyboard::IsKeyPressed ( sf::Keyboard::Up ) && ComUp == 0 ||
									ComUp > 0 && comup.GetElapsedTime() > 120 ) 
									 {
										ComUp++;
										comup.Reset();
										if ( !goingLeft ) 
											 charSprite1.Move ( +5, 0 );
										else 
										{
											charSprite1.Move ( -5, 0 );
										}

									 }

									switch ( ComUp )
								{	
								case 1: charSprite1.SetTexture ( comUpTexture1 ); break;
								case 2: charSprite1.SetTexture ( comUpTexture2 ); break;
								case 3: charSprite1.SetTexture ( comUpTexture3 ); break;
								case 4: charSprite1.SetTexture ( comUpTexture4 ); break;
								case 5: charSprite1.SetTexture ( comUpTexture5 ); break;
								case 6: charSprite1.SetTexture ( comUpTexture6 ); break;
								case 7: charSprite1.SetTexture ( comUpTexture7 ); break;
								case 8: charSprite1.SetTexture ( comUpTexture8 ); break;
								case 9: charSprite1.SetTexture ( comUpTexture9 ); break;
								case 10: charSprite1.SetTexture ( comUpTexture10 ); break;
								case 11: charSprite1.SetTexture ( comUpTexture11 ); break;
								case 12: charSprite1.SetTexture ( comUpTexture12 ); break;
								case 13: charSprite1.SetTexture ( comUpTexture13 ); break;
								case 14: charSprite1.SetTexture ( comUpTexture14 ); break;
								case 15: if ( sf::Keyboard::IsKeyPressed ( sf::Keyboard::Right ) || ( sf::Keyboard::Left ) )
										 {
											 walking = ( walking + 1 );
											 ComUp = 0;
											 break;
										 }
										 else 
									 {
										ComUp = 0;
										charSprite1.SetTexture ( standTexture1 ); 
										break;
										 }
								} 

				window.Clear();
				window.Draw ( SpriteTlo2 );
				window.Draw ( SpriteTlo1 );
				window.Draw ( charSprite1 );
				window.Display();
				}
					return 0;
		}